package com.mrd.gtimp.business.entity;

import com.mrd.gtimp.base.entity.User;
import com.mrd.util.PkCleanerUtil;
import com.mrd.util.PkConfig;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;

/**
 * <p>
 * application name: sample
 * <p>
 * copyright: Copyright@2012 明睿达科技有限公司
 */
/**
 * 拖车业务信息
 * @author winaya
 */
@Entity(name = "T_BIZ_TRAIL")
public class Trail extends BaseBusiness implements Serializable {

	private static final long	serialVersionUID	= 1L;
	/**
	 * id
	 */
	// @Id
	// @GeneratedValue(generator = "paymentableGenerator")
	// @GenericGenerator(name = "paymentableGenerator", strategy = "uuid")
	// @Column(name = "ID")
	// private String id;
	/**
	 * 装货信息
	 */
	@OneToMany(mappedBy = "trail")
	@Cascade(value = {CascadeType.SAVE_UPDATE, CascadeType.DELETE })
	private List<GoodAddress>	gdes;
	/**
	 * 前置信息，海运订舱id和so存在一个即可
	 */
	/**
	 * so号码
	 */
	@Column(name = "SO")
	private String	          so;

	/**
	 * PI号
	 */
	@Column(name = "PI")
	private String	          pi;

	/**
	 * 柜总量
	 */
	@Column(name = "CONTAINER_TOTLE")
	private String	          containerTotle;

	/**
	 * 报关票数登记
	 */
	@Column(name = "DECLARATION_COUNT")
	private String	          declarationCount;

	/**
	 * 是否为常用模板
	 */
	@Column(name = "COMMON_TEMPLATE")
	private String	          commonTemplate;

	/**
	 * 电子版SO
	 */
	@OneToOne
	@JoinColumn(name = "SO_FILE_ID")
	private Attachment	      soDoc;

	/**
	 * 交接单号
	 */
	@Column(name = "REQ_NO")
	private String	          reqNo;
	/**
	 * 反馈信息在装货信息的车内
	 */
	/**
	 * 拖车状态
	 */
	@Column(name = "STATE")
	private String	          trailState;

	/**
	 * 常用模板名
	 */
	@Column(name = "COMMON_TEMPLATE_NAME")
	private String	          commonTemplateName;

	/**
	 * 操作类型
	 */
	// @Column(name = "OPERATION_TYPE")
	// private String operationType;
	/**
	 * 提箱出闸时间
	 */
	// @Column(name = "PASS_OUT_TIME")
	// private Date SuitcasePassOutTime;
	/**
	 * 收箱出闸时间
	 */
	// @Column(name = "PASS_OUT_TIME")
	// private Date revokePassOutTime;
	// public String getId() {
	// return id;
	// }
	//
	// public void setId(String id) {
	// this.id = id;
	// }
	public List<GoodAddress> getGdes() {
		return gdes;
	}

	public void setGdes(List<GoodAddress> gdes) {
		this.gdes = gdes;
	}

	public String getTrailState() {
		return trailState;
	}

	public void setTrailState(String trailState) {
		this.trailState = trailState;
	}

	public Attachment getSoDoc() {
		return soDoc;
	}

	public void setSoDoc(Attachment soDoc) {
		this.soDoc = soDoc;
	}

	public Trail(String trailString) {
		fromString(trailString);
	}

	public Trail() {
		super();
	}

	/*
	 * (non-Javadoc)
	 * @see com.mrd.gtimp.business.entity.BaseBusiness#fromString(java.lang.String)
	 */
	@Override
	public BaseBusiness fromString(String businessString) {
		return null;
	}

	/*
	 * (non-Javadoc)
	 * @see com.mrd.gtimp.business.entity.BaseBusiness#toString()
	 */
	@Override
	public String toString() {
		return null;
	}

	public String getSo() {
		return so;
	}

	public void setSo(String so) {
		this.so = so;
	}

	public String getPi() {
		return pi;
	}

	public void setPi(String pi) {
		this.pi = pi;
	}

	public String getContainerTotle() {
		return containerTotle;
	}

	public void setContainerTotle(String containerTotle) {
		this.containerTotle = containerTotle;
	}

	public String getDeclarationCount() {
		return declarationCount;
	}

	public void setDeclarationCount(String declarationCount) {
		this.declarationCount = declarationCount;
	}

	public String getReqNo() {
		return reqNo;
	}

	public void setReqNo(String reqNo) {
		this.reqNo = reqNo;
	}

	public String getCommonTemplate() {
		return commonTemplate;
	}

	public void setCommonTemplate(String commonTemplate) {
		this.commonTemplate = commonTemplate;
	}

	public String getCommonTemplateName() {
		return commonTemplateName;
	}

	public void setCommonTemplateName(String commonTemplateName) {
		this.commonTemplateName = commonTemplateName;
	}

	@Override
	public void clearPk() throws Exception {
		PkConfig[] configs = {new PkConfig("id", String.class),
		        new PkConfig("CREATOR", String.class), new PkConfig("CTIME|O", Date.class),
		        new PkConfig("MODIFIER", String.class), new PkConfig("MTIME|O", Date.class),
		        new PkConfig("CONFIRM_TIME|O", Date.class),
		        new PkConfig("VALIDATE_TIME|O", Date.class),
		        new PkConfig("validator_ext", String.class),
		        new PkConfig("validator|O", User.class), new PkConfig("upload_time|O", Date.class),
		        new PkConfig("uploader_ext", String.class), new PkConfig("uploader|O", User.class),
		        new PkConfig("finish_time|O", Date.class),
		        new PkConfig("finisher_ext", String.class), new PkConfig("finisher|O", User.class),
		        new PkConfig("so", String.class), new PkConfig("trailState", String.class),
		        new PkConfig("soDoc|O", Attachment.class) };
		PkCleanerUtil.clearPk(this, configs);
		for(GoodAddress ga : gdes) {
			PkConfig[] gconfigs = {new PkConfig("id", String.class),
			        new PkConfig("trail|O", Trail.class), new PkConfig("carmsges|O", List.class) };
			PkCleanerUtil.clearPk(ga, gconfigs);
			/*
			 * for(Container c : ga.getContainers()) {
			 * PkConfig[] cconfigs = {new PkConfig("id", String.class),
			 * new PkConfig("booking|O", Booking.class),
			 * new PkConfig("carMsg|O", CarMsg.class) };
			 * //PkCleanerUtil.clearPk(c, cconfigs);
			 * }
			 */
		}
	}

}
